<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <!--头部固定引用-->
  <meta charset="utf-8">
  <meta name="full-screen" content="yes">
  <meta name="x5-fullscreen" content="true">
  <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
  <link rel="stylesheet" href="../../css/base.css">
  <link rel="stylesheet" href="../../plugin/mescroll/css/mescroll.min.css">
  <!--固定引用结束,自定义引用添加在下面-->
  <title>JT2</title>
  <!--页面样式添加在这里，多看看base。css里面的公共样式，大部分常用的都有，避免使用独立css文件为单独页面设置样式，避免随意添加样式到公共样式-->
  <style>
      .board-listDetails ul{
        list-style: none;
        margin: 0;
        padding: 0;
      }
      .board-listDetails ul li {
          padding: 0.36rem 0.32rem 0.36rem 0.32rem;
          position: relative;
          height: 2.36rem;
      }
      .board-listDetails ul li .content-left {
          position: absolute;
          left: 0.32rem;
      }
      .board-listDetails ul li .content-left-main {
        width: 4.52rem;
        height: 0.88rem;
        font-family: PingFangSC-Medium;
        font-size: 0.3rem;
        letter-spacing: 0;
        text-align: left;
        line-height: 0.44rem;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .board-listDetails ul li .content-left-litterText {
        font-family: PingFangSC-Regular;
        font-size: 0.24rem;
        letter-spacing: 0;
        text-align: left;
        margin-top: 0.42rem;
      }
      .board-listDetails ul li .content-left-litterText span:nth-child(1){
          margin-right: 0.28rem;
      }
      .board-listDetails ul li .content-right {
        position: absolute;
        right: 0.32rem;
        width: 2.12rem;
        height: 1.3rem;
        border-radius: 0.08rem;
      }
      .board-listDetails ul li .content-right img {
        width: 2.12rem;
        height: 1.3rem;
        border-radius: 0.08rem;
      }
      .mescroll{
			position: fixed;
			top: 0;
			bottom: 0;
			height: auto; /*如设置bottom:50px,则需height:auto才能生效*/
		}
  </style>
</head>
<!--尽量不要在body上添加样式，除了背景色-->
<body>
<div>
  <!-- 列表 -->
  <div class="board-listDetails mescroll" id='mescroll'>
      <ul>
      </ul>
  </div>
</div>
</body>
<!--下面五个文件为固定引用，自己根据情况调整路径，不要跟换引入顺序，其他引用添加在后面-->
<script src="../../js/dict.js"></script>
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/checkJsBridge.js"></script>
<script src="../../js/utils.js"></script>
<script src="../../js/api.js"></script>
<script src="../../plugin/mescroll/js/mescroll.min.js"></script>
<!--固定引用结束-->
<!--避免一个页面包含过多功能，减少js重绘页面，推荐分功能，分页面-->
<script>
  let pageNum = 1
  let funcCode
  let hasNext = true
  let mescroll
  /*固定页面初始化方法，用于替代$(function(){}),param为url参数，Object类型*/
  //资讯列表页面复用，需要安卓IOS传funcCode来获取对应的页面列表
  function initPage(params) {
    console.log(params)
    funcCode = params.funcCode

    mescroll = new MeScroll('mescroll',{
      down: {
            // use: false,
            auto : false,
            callback: function() {
                pageNum =1
                $('.board-listDetails ul').empty()
                getList({'funcCode':funcCode,'pageNum':1})
                // mescroll.endSuccess()
            }
				  },
      up:{
        pageNum: pageNum,
        callback:getList,
        htmlNodata: '<p class="upwarp-nodata">-- 暂无更多数据 --</p>',
        noMoreSize: 10
      }
    })

    $('.board-listDetails ul').empty()
    // getList(params)


  }

  /*页面所在窗口由后台前台时触发的方法,param为url参数，Object类型*/
  function startPage(params) {

  }

  function reLoadPage() {
    pageNum = 1
    $('.board-listDetails ul').empty()
    getList({'funcCode':funcCode,'pageNum':1})
  }
  //获取列表
  function getList(params){
    //005001
    Server.realTimeInfo.getinfoList({'funcCode':funcCode,'pageNum':params.pageNum||pageNum,'pageSize':10}).then(res => {
    // Server.realTimeInfo.getinfoList({'funcCode':'004005','pageNum':params.pageNum||pageNum,'pageSize':10}).then(res => {
      console.log(res)
      // alert(pageNum,JSON.stringify(res.list))
        if(res.code === 0){
            let data = res.list
            //判断是否有下一页
            if(data.length < 10){
              hasNext = false
            }else{
              pageNum++
              hasNext = true
            }

            data.map((item,index) => {
                let creatTime = item.issuerDttm*1000
                let nowTime = +new Date().valueOf()
                let year = new Date(creatTime).getFullYear()
                let month = new Date(creatTime).getMonth()+1<10?'0'+(new Date(creatTime).getMonth()+1):new Date(creatTime).getMonth()+1
                let day = new Date(creatTime).getDate()<10?'0'+new Date(creatTime).getDate():new Date(creatTime).getDate()
                let hour = new Date(creatTime).getHours()<10?'0'+ new Date(creatTime).getHours(): new Date(creatTime).getHours()
                let minute = new Date(creatTime).getMinutes()<10?'0'+new Date(creatTime).getMinutes():new Date(creatTime).getMinutes()
                if(nowTime - creatTime < 30*60*1000){
                  if(nowTime - creatTime < 1*60*1000){
                    item.issuerDttm = '刚刚'
                  }else{
                    item.issuerDttm = parseInt((nowTime - creatTime)/1000/60)+'分钟前'
                  }
                }else if(nowTime - creatTime < 24*60*60*1000){
                    if(nowTime-creatTime < 60*60*1000){
                      item.issuerDttm = '1小时前'
                    }else {
                      item.issuerDttm = parseInt((nowTime - creatTime)/1000/60/60)+'小时前'
                    }
                }else if(new Date().getDate()-new Date(creatTime).getDate()==1 && new Date().getMonth()==new Date(creatTime).getMonth() && new Date().getFullYear() == new Date(creatTime).getFullYear()){
                  item.issuerDttm = '昨天'+hour+":"+minute
                }else{
                  item.issuerDttm = year +'-'+ month+'-'+day+' '+hour+':'+minute
                }
            })

            data.map((v,i) => {
                let li =
                `<li onclick="gozixundetails({'infoId':'${v.infoId}','infoType':'${v.infoType}','funcCode':'${v.funcCode}'},this)" style="background:${configColorType==='1'?'#222222':'#ffffff'};border-bottom:${configColorType==='1'?'0.02rem solid #131313':'0.02rem solid #f7f7f7'}">
                    <div class="content-left">
                      <div class="content-left-main" style="width:${v.coverImgUrl?'':'100%'};color:${configColorType==='1'?'rgba(255,255,255,0.80)':'#222222'};padding-right:0.32rem;">${v.mainTitle}</div>
                      <div class="content-left-litterText" style="width:${v.coverImgUrl?'':'100%'};color:${configColorType==='1'?'rgba(255,255,255,0.80)':'rgba(34,34,34,0.45)'}">
                        <span>${v.issuerDttm}</span>
                      </div>
                    </div>
                    <div class="content-right" style="display:${v.coverImgUrl?'block':'none'}">
                      <img src="${v.coverImgUrl}" alt="">
                    </div>
                </li>`

                $('.board-listDetails ul').append(li)
            })
              mescroll.endSuccess(10, hasNext)
        }else{
            // jsBridge.toast('数据异常')
        }
    })
  }
  //点击某一项去资讯详情页面
  function gozixundetails(params1,params2){
    // console.log(params1,params2)
    // console.log($(params2).children().eq(0).children().eq(1).children().eq(1).text())
    let num = $(params2).children().eq(0).children().eq(1).children().eq(1).text()
    $(params2).children().eq(0).children().eq(1).children().eq(1).text(+num+1)
    jsBridge.openWindow('/html/details/Information-details.html?infoId='+params1.infoId+'&infoType='+params1.infoType+'&funcCode='+params1.funcCode+'&isopencomment=0',{}, {noBar: false})
  }
  //滑动加载下一页
  // document.addEventListener('scroll',function(){
  //   let top = $('.board-listDetails ul').offset().top
  //   let height = $('.board-listDetails ul').height()
  //   let maxHeight = document.body.offsetHeight
  //   let scroll = $(document).scrollTop()
  //   if(Math.round(top+height-maxHeight) === Math.round(scroll) ){
  //     pageNum++
  //     getList({'funcCode':funcCode,'pageNum':pageNum})
  //   }
  // })
</script>
</html>
